package com.shuma.auth.controller;

import com.shuma.auth.entity.RestBean;
import com.shuma.auth.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

@RestController
@Slf4j
public class CommonController {

    @Resource
    private AliOSSUtils aliOSSUtils;

    /**
     * 上传图片到阿里云OSS
     * @param file
     * @return
     * @throws IOException
     */
    @PostMapping("common/uploadImage")
    public RestBean<String> uploadImage(MultipartFile file) throws IOException {
        String fileName = aliOSSUtils.upload(file);
        return RestBean.success(fileName);
    }
}
